/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#include "stdafx.h"
#include "C_数值插座.h"

#include "list/list数值插座.h"
#include "list/list矢量插座.h"
#include "list/list元素插座.h"
#include "list/list物理物体插座.h"
#include "list/list物体插座.h"
#include "通用插座.h"

#include "节点/编译声明代码.h"


using namespace std;




C_行文本插座::C_行文本插座(wstring name)
	:C_插座基类(name, E_值类型::e_Type_LineText)
{
}

C_行文本插座::~C_行文本插座() {
	C_插座基类::~C_插座基类();
}

void * C_行文本插座::f_getData(uint8 线程ID) {
	C_插座基类* socket = f_getLinkOutSocket();
	if (socket) {
		if (socket->m_Type == E_值类型::e_Type_LineText) {
			return dynamic_cast<C_行文本插座*>(socket)->f_getData(线程ID);
		}
	}
	return &m_文本;
}

void C_行文本插座::f_setData(void* data, uint8 线程ID) {
	m_文本 = *(string*)data;
}

PyObject* C_行文本插座::f_bl_传入数据(PyObject* bl_data) {
	//m_文本 = f_Py字符串转string(bl_data);
	return nullptr;
}

PyObject* C_行文本插座::f_输出_bl数据(PyObject* bl_data) {
	PyObject* data = 0;
	if (bl_data != (PyObject*)0) {
		//data = f_string转PyObject(m_文本);
	}
	else {
		data = PyList_New(1);
		//PyList_SetItem(data, 0, f_string转PyObject(m_文本));
	}
	return data;
}










C_F32插座::C_F32插座(wstring name, float32* mapVal) :C_插座基类(name, E_值类型::e_Type_F32) {
	if (mapVal) {
		m_Value = mapVal;
		m_映射指针 = true;
	}
	else {
		m_Value = (float32*)malloc(sizeof(float32));
		(*m_Value) = 0.0f;
	}
}

C_F32插座::~C_F32插座() {
	C_插座基类::~C_插座基类();
}

void C_F32插座::f_update(C_插座基类 * 连接到的输入节点, C_节点基类 * node) {

}

void* C_F32插座::f_getData(uint8 线程ID) {
	C_插座基类* socket = f_getLinkOutSocket(线程ID);
	if (socket) {
		if (socket->m_Type == E_值类型::e_Type_F32) {
			return socket->f_getData(0);
		}
		else if (socket->m_Type == E_值类型::e_Type_I32) {
			(*m_Value) = *((int32*)(dynamic_cast<C_I32插座*>(socket)->f_getData(0)));
			return m_Value;
		}
		else if (socket->m_Type == E_值类型::e_Type_UI32) {
			(*m_Value) = DEF_UI32插座数据(socket);
			return m_Value;
		}
		else if (socket->m_Type == E_值类型::e_Type_I8) {
			(*m_Value) = DEF_I8插座数据(socket, 0);
			return m_Value;
		}
		else if (socket->m_Type == E_值类型::e_Type_F32_1D) {
			const auto& v = DEF_F32插座_1D数据(socket);
			(*m_Value) = v->count;
		}
		else if (socket->m_Type == E_值类型::e_Type_I32_1D) {
			const auto& v = DEF_I32插座_1D数据(socket);
			(*m_Value) = v->count;
		}
		else if (socket->m_Type == E_值类型::e_Type_UI32_1D) {
			const auto& v = DEF_UI32插座_1D数据(socket);
			(*m_Value) = v->count;
		}
		else if (socket->m_Type == E_值类型::e_Type_Vec2_1D) {
			const auto& v = DEF_Vec2插座_1D数据(socket);
			(*m_Value) = v->count;
		}
		else if (socket->m_Type == E_值类型::e_Type_Vec3_1D) {
			const auto& v = DEF_Vec3插座_1D数据(socket);
			(*m_Value) = v->count;
		}
		else if (socket->m_Type == E_值类型::e_Type_iVec2_1D) {
			const auto& v = DEF_iVec2插座_1D数据(socket);
			(*m_Value) = v->count;
		}
		else if (socket->m_Type == E_值类型::e_Type_iVec3_1D) {
			const auto& v = DEF_iVec3插座_1D数据(socket);
			(*m_Value) = v->count;
		}
		else if (socket->m_Type == E_值类型::e_Type_uVec2_1D) {
			const auto& v = DEF_uVec2插座_1D数据(socket);
			(*m_Value) = v->count;
		}
		else if (socket->m_Type == E_值类型::e_Type_F32_Array1D) {
			const auto& v = DEF_F32_Array1D插座数据(socket, 0);
			if (v->size()) {
				(*m_Value) = (*v).at(0);
			}
		}
	}
	return m_Value;
}

bool C_F32插座::f_getBool(const uvec4& id) {
	return (*m_Value);
}

void C_F32插座::f_setData(void* data, uint8 线程ID) {
	C_插座基类::f_setData(data);
	(*m_Value) = *(float32*)data;
}

void C_F32插座::f_绑定指针(void* data) {
	if (!m_映射指针) {
		free(m_Value);
	}
	m_Value = (float32*)data;
}

E_JIT_FunParam C_F32插座::f_getJIT参数(uint8 线程ID, uint16 in_ID) {
	m_JIT参数ID = in_ID;
	E_JIT_FunParam 参数;
	参数.m_data = f_getData(线程ID);
	参数.m_type = m_Type;
	参数.m_Num = 0;
	return 参数;
}

std::string C_F32插座::f_构建变量代码(int32 loc) {
	C_插座基类* socket = f_getLinkOutSocket(loc);

	std::string code;
	if (socket) {
		if (socket->m_Type == E_值类型::e_Type_F32) {
			m_Code = socket->f_getCode(loc);
			return "";
		}

		m_Code = m_pNode->f_getName() + f_getName() + f_整数值转字符串(loc) + "new_val_to_f32";
		auto val = socket->f_getCode(loc);
		if(val.empty()) val = "0";

		code = "float32 " + m_Code + " = ";
		switch (socket->m_Type) {
			case E_值类型::e_Type_I8:
			case E_值类型::e_Type_I32:
			case E_值类型::e_Type_UI32:
			case E_值类型::e_Type_F64:
				code += "((float32)" + socket->f_getCode(loc) + ");\n";
				break;


			case E_值类型::e_Type_多边形边1D:
			case e_Type_I8_1D:
			case e_Type_I32_1D:
			case e_Type_UI32_1D:
			case e_Type_UI32_2D:
			case e_Type_F32_1D:
			//case e_Type_F32_2D:
			case e_Type_iVec2_1D:
			case e_Type_iVec3_1D:
			case e_Type_iVec3_2D:
			case e_Type_uVec2_1D:
			case e_Type_uVec3_1D:
			case e_Type_Vec2_1D:
			case e_Type_Vec3_1D:
			case e_Type_Vec3_2D: {
				code += socket->f_getCode(loc) + "->count;\n";
				break;
			}

			default:
				//m_Code = socket->f_getCode();
				//if(m_Code.empty()) code += "0;\n";
				std::cout << "F32插座: 输入数据没有实现转换类型" << std::endl;
				return "";
		}
		
	}
	else {
		C_插座基类::f_构建变量代码(loc);
		return "";
	}
	
	return code;
}

bool C_F32插座::f_接入插座是否匹配(E_值类型 type) {
	switch (type) {
		case e_Type_I8:
		case e_Type_I32:
		case e_Type_UI32:
		case e_Type_F32:
		case e_Type_I8_1D:
		case e_Type_I32_1D:
		case e_Type_UI32_1D:
		case e_Type_UI32_2D:
		case e_Type_F32_1D:
		case e_Type_Vec2_1D:
		case e_Type_Vec3_1D:
		case e_Type_Vec3_2D:
		case e_Type_iVec2_1D:
		case e_Type_iVec3_1D:
		case e_Type_iVec3_2D:
		case e_Type_uVec2_1D:
		case e_Type_uVec3_1D:
		case E_值类型::e_Type_多边形边1D:
		case E_值类型::e_插座Type_引用数据:
			return true;
	}
	return false;
}

void C_F32插座::f_读取(FILE* f) {
	C_插座基类::f_读取(f);

	fread(m_Value, sizeof(float32), 1, f);
}

void C_F32插座::f_写入(FILE* f) {
	C_插座基类::f_写入(f);

	fwrite(m_Value, sizeof(float32), 1, f);
}

void C_F32插座::f_Copy(const C_插座基类* socket) {
	C_插座基类::f_Copy(socket);

	switch (socket->m_Type) {
	case E_值类型::e_Type_F32: {
		(*m_Value) = *(dynamic_cast<const C_F32插座*>(socket)->m_Value);
		break;
	}
	case E_值类型::e_Type_F32_1D: {
		//(*m_Value) = *(dynamic_cast<const C_F32_1D插座*>(socket)->m_Value);
		break;
	}
	}
}


PyObject * C_F32插座::f_bl_传入数据(PyObject * bl_data) {
	m_pNode->f_set是否要更新(true);
	(*m_Value) = PyFloat_AsDouble(bl_data);
	return nullptr;
}

PyObject * C_F32插座::f_输出_bl数据(PyObject * bl_data) {
	PyObject* data = 0;
	if (bl_data == (PyObject*)0xffffffff) {
		//data = Py_BuildValue("[f]", DEF_F32插座Value(this, 线程ID));
	}
	else {
		//data = Py_BuildValue("i", DEF_F32插座Value(this, 线程ID));
	}
	return data;
}












C_I8插座::C_I8插座(wstring name) :C_插座基类(name, E_值类型::e_Type_I8) {
	m_Value = (int8*)malloc(sizeof(int8));
	(*m_Value) = 0;
}

C_I8插座::~C_I8插座() {
	free(m_Value);
	C_插座基类::~C_插座基类();
}

void* C_I8插座::f_getData(uint8 线程ID) {
	C_插座基类* socket = f_getLinkOutSocket();
	if (socket) {
		if (socket->m_Type == E_值类型::e_Type_I8) {
			return dynamic_cast<C_I8插座*>(socket)->f_getData(线程ID);
		}
		else if (socket->m_Type == E_值类型::e_Type_I32) {
			*m_Value = *((int32*)(dynamic_cast<C_I32插座*>(socket)->f_getData(线程ID)));
		}
		else if (socket->m_Type == E_值类型::e_Type_F32) {
			*m_Value = DEF_F32插座数据(socket, 线程ID);
		}
		else if (socket->m_Type == E_值类型::e_Type_I8_1D) {
			auto v = DEF_I8插座_1D数据(socket);
			*m_Value = v->count;
		}
		else if (socket->m_Type == E_值类型::e_Type_I32_1D) {
			auto v = DEF_I32插座_1D数据(socket);
			*m_Value = v->count;
		}
		else if (socket->m_Type == E_值类型::e_Type_I32_1D) {
			auto v = DEF_F32插座_1D数据(socket);
			*m_Value = v->count;
		}
	}
	return m_Value;
}

void C_I8插座::f_setData(void* data, uint8 线程ID) {
	(*m_Value) = *((int8*)data);
}

std::string C_I8插座::f_构建变量代码(int32 loc) {
	C_插座基类* socket = f_getLinkOutSocket(loc);

	std::string code;
	if (socket) {
		if(socket->m_Type == E_值类型::e_Type_I8) {
			m_Code = socket->f_getCode(loc);
			return "";
		}

		m_Code = m_pNode->f_getName() + f_getName() + f_整数值转字符串(loc) + "new_val_to_f32";
		switch (socket->m_Type) {
		case e_Type_I8: 
		case e_Type_F32:
		case e_Type_F64:
		case e_Type_I32:
		case e_Type_UI32:
		case e_Type_I64:
			code += DEF_S(int8)" ";
			code += m_Code + " = ((float32)" + socket->f_getCode(loc) + ");\n";
			break;
		case E_值类型::e_Type_I8_1D:
		//case E_值类型::e_Type_I64_1D:
		case E_值类型::e_Type_I32_1D:
		case E_值类型::e_Type_F32_1D:
		case E_值类型::e_Type_Vec3_1D:
		case E_值类型::e_Type_Vec4_1D:
		case E_值类型::e_Type_多边形_1D:
		case E_值类型::e_Type_多边形边1D:
		case e_Type_uVec2_1D: {
			m_Code = f_代码构建_Array数组数量(socket->f_getCode(loc));
			break;
		default:
			return socket->f_getCode(loc);
		}
		}

	}
	else {
		C_插座基类::f_构建变量代码(loc);
	}

	return code;
}

void C_I8插座::f_读取(FILE* f) {
	C_插座基类::f_读取(f);

	fread(m_Value, sizeof(int8), 1, f);
}

void C_I8插座::f_写入(FILE* f) {
	C_插座基类::f_写入(f);

	fwrite(m_Value, sizeof(int8), 1, f);
}

void C_I8插座::f_Copy(const C_插座基类* node) {
	C_插座基类::f_Copy(node);

	auto* socket = dynamic_cast<const C_I8插座*>(node);
	if (socket) {
		(*m_Value) = *(socket->m_Value);
	}
	
}






C_F64插座::C_F64插座(wstring name, float64* mapVal) :C_插座基类(name, E_值类型::e_Type_F64) {
	if (mapVal) {
		m_Value = mapVal;
		m_映射指针 = true;
	}
	else {
		m_Value = (float64*)malloc(sizeof(float64));
		(*m_Value) = 0.0f;
	}
}

C_F64插座::~C_F64插座(){
	C_插座基类::~C_插座基类();
}

void* C_F64插座::f_getData(uint8 线程ID) {
	C_插座基类* socket = f_getLinkOutSocket(线程ID);
	if (socket) {
		if (socket->m_Type == E_值类型::e_Type_F64) {
			return socket->f_getData(0);
		}
		else if (socket->m_Type == E_值类型::e_Type_F32) {
			(*m_Value) = DEF_F32插座数据(socket);
		}
		else if (socket->m_Type == E_值类型::e_Type_I32) {
			(*m_Value) = *((int32*)(dynamic_cast<C_I32插座*>(socket)->f_getData(线程ID)));
			return m_Value;
		}
		else if (socket->m_Type == E_值类型::e_Type_F32_Array1D) {
			const auto& v = DEF_F32_Array1D插座数据(socket, 0);
			if (v->size()) {
				(*m_Value) = (*v).at(0);
			}
		}
	}
	return m_Value;
}

void C_F64插座::f_setData(void* data, uint8 线程ID) {
	C_插座基类::f_setData(data);
	(*m_Value) = *(float64*)data;
}

bool C_F64插座::f_接入插座是否匹配(E_值类型 type) {
	switch (type) {
	case e_Type_I32:
	case e_Type_UI32:
	case e_Type_F32:
	case e_Type_F64:
	case e_Type_I32_1D:
	case e_Type_F32_1D:
	case e_Type_Vec2_1D:
	case e_Type_Vec3_1D:
	case e_Type_uVec2_1D:
	case e_Type_uVec3_1D:
	case E_值类型::e_Type_多边形边1D:
	case E_值类型::e_插座Type_引用数据:
		return true;
	}
	return false;
}

void C_F64插座::f_绑定指针(void* data) {
	if (!m_映射指针) {
		free(m_Value);
	}
	m_Value = (float64*)data;
}

void C_F64插座::f_读取(FILE* f) {
	C_插座基类::f_读取(f);
	fread(m_Value, sizeof(float64), 1, f);
}

void C_F64插座::f_写入(FILE* f) {
	C_插座基类::f_写入(f);
	fwrite(m_Value, sizeof(float64), 1, f);
}





C_I32插座::C_I32插座(wstring name, int32* mapVal) :C_插座基类(name, E_值类型::e_Type_I32) {
	//if (mapVal) {
	//	m_Value = mapVal;
	//	m_映射指针 = true;
	//}
	//else {
	//	m_Value = (int32*)malloc(sizeof(int32));
	//	(*m_Value) = 0.0f;
	//}

	m_转换值 = 0;
	m_默认值 = 0;
	m_Value = &m_默认值;
}

C_I32插座::~C_I32插座() {
	C_插座基类::~C_插座基类();
}

void C_I32插座::f_update(C_插座基类 * 连接到的输入节点, C_节点基类 * node)
{
}

void* C_I32插座::f_getData(uint8 线程ID) {
	C_插座基类* socket = f_getLinkOutSocket();
	if (socket) {
		switch (socket->m_Type) {
			case E_值类型::e_Type_I32 : return dynamic_cast<C_I32插座*>(socket)->f_getData(线程ID);
		 
			case E_值类型::e_Type_I8: m_转换值 = DEF_I8插座数据(socket, 0); break;
			
			case E_值类型::e_Type_F32: m_转换值 = *( (float32*)(socket->f_getData(线程ID)) ); break;
			
			case E_值类型::e_Type_UI32: m_转换值 = DEF_UI32插座数据(socket); break;
		
			case E_值类型::e_Type_F32_Array1D: {
				const auto& v = DEF_F32_Array1D插座数据(socket, 0);
				if (v->size()) {
					m_转换值 = (*v).at(0);
				}
				break;
			}
			case E_值类型::e_Type_F32_1D: {
				const auto& v = DEF_F32插座_1D数据(socket, 0);
				m_转换值 = v->count;
				break;
			}
			case E_值类型::e_Type_I32_1D: {
				const auto& v = DEF_I32插座_1D数据(socket, 0);
				m_转换值 = v->count;
				break;
			}
			case E_值类型::e_Type_UI32_1D: {
				const auto& v = DEF_UI32插座_1D数据(socket, 0);
				m_转换值 = v->count;
				break;
			}
			case E_值类型::e_Type_Vec2_1D: {
				const auto& v = DEF_Vec2插座_1D数据(socket, 0);
				m_转换值 = v->count;
				break;
			}
			case E_值类型::e_Type_Vec3_1D: {
				const auto& v = DEF_Vec3插座_1D数据(socket, 0);
				m_转换值 = v->count;
				break;
			}
			case E_值类型::e_Type_iVec2_1D: {
				const auto& v = DEF_iVec2插座_1D数据(socket, 0);
				m_转换值 = v->count;
				break;
			}
			case E_值类型::e_Type_iVec3_1D: {
				const auto& v = DEF_iVec3插座_1D数据(socket, 0);
				m_转换值 = v->count;
				break;
			}
			
		}
		m_Value = &m_转换值;
	}
	else {
		m_Value = &m_默认值;
	}
	return m_Value;
}

//bool C_I32插座::f_getBool(const uvec4& id) {
//	int32 v = (DEF_I32插座数据(this, 0));
//	return v;
//}

void C_I32插座::f_setData(void * data, uint8 线程ID) {
	C_插座基类::f_setData(data);
	if (data) {
		(*m_Value) = *(int32*)data;
	}
	else {

	}
}

std::string C_I32插座::f_构建变量代码(int32 loc) {
	C_插座基类* socket = f_getLinkOutSocket(loc);

	if (socket) {
		if (socket->m_Type == E_值类型::e_Type_I32) {
			m_Code = socket->f_getCode(loc);
			return "";
		}

		std::string code;

		m_Code = m_pNode->f_getName() + f_getName() + f_整数值转字符串(loc) + "_new_val_to_i32";
		code = "int32 " + m_Code + " = ";
		switch (socket->m_Type) {
			case e_Type_I8:
			case e_Type_I32:
			case e_Type_UI32:
			case e_Type_F64:
			case e_Type_F32: {
				code += "int32(" + socket->f_getCode(loc) + ");\n";
				break;

			case E_值类型::e_Type_多边形边1D:
			case e_Type_I8_1D:
			case e_Type_I32_1D:
			case e_Type_F32_1D:
			case e_Type_Vec2_1D:
			case e_Type_Vec3_1D:
			case e_Type_Vec3_2D:
			case e_Type_Vec4_1D: 
			case e_Type_iVec3_1D:
			case e_Type_iVec3_2D: {
				code += socket->f_getCode(loc) + "->count;\n";
				break;
			}

			default:
				std::cout<<"error:i32查找 输入类型没有对于转换方式"<<std::endl;
				return socket->f_getCode(loc);
			}
		}

		return code;
	}

	return C_插座基类::f_构建变量代码(loc);
}

bool C_I32插座::f_接入插座是否匹配(E_值类型 type) {
	switch (type) {
		case e_Type_I8:
		case e_Type_I32:
		case e_Type_UI32:
		case e_Type_F32:
		case e_Type_I8_1D:
		case e_Type_I32_1D:
		case e_Type_F32_1D:
		case e_Type_Vec2_1D:
		case e_Type_Vec3_1D:
		case e_Type_Vec3_2D:
		case e_Type_iVec3_1D:
		case e_Type_iVec3_2D:
		case e_Type_uVec2_1D:
		case e_Type_uVec3_1D:
		case E_值类型::e_Type_多边形边1D:
		case E_值类型::e_插座Type_引用数据:
			return true;
	}
	return false;
}

void C_I32插座::f_读取(FILE* f) {
	C_插座基类::f_读取(f);

	fread(m_Value, sizeof(int32), 1, f);
}

void C_I32插座::f_写入(FILE* f) {
	C_插座基类::f_写入(f);

	fwrite(m_Value, sizeof(int32), 1, f);
}

void C_I32插座::f_Copy(const C_插座基类* node) {
	C_插座基类::f_Copy(node);
	(*m_Value) = *(dynamic_cast<const C_I32插座*>(node)->m_Value);
}

void C_I32插座::f_绑定指针(void* data) {
	if (m_Value == data) return;

	if (!m_映射指针) {
		free(m_Value);
	}
	m_Value = (int32*)data;
	m_映射指针 = true;
}






C_UI32插座::C_UI32插座(wstring name, uint32* mapVal) :C_插座基类(name, E_值类型::e_Type_UI32) {
	/*if (mapVal) {
		m_Value = mapVal;
		m_映射指针 = true;
	}
	else {
		m_Value = (uint32*)malloc(sizeof(uint32));
		(*m_Value) = 0;
		m_映射指针 = false;
	}*/

	m_默认值 = 0;
	m_转换值 = 0;
	m_Value = &m_默认值;
}

C_UI32插座::~C_UI32插座() {
	//if(!m_映射指针) free(m_Value);
	C_插座基类::~C_插座基类();
}

void* C_UI32插座::f_getData(uint8 连接线ID) {
	C_插座基类* socket = f_getLinkOutSocket(连接线ID);
	if (socket) {
		if (socket->m_Type == E_值类型::e_Type_UI32) {
			return dynamic_cast<C_UI32插座*>(socket)->f_getData(连接线ID);
		}
		else if (socket->m_Type == E_值类型::e_Type_I8) {
			m_转换值 = DEF_I8插座数据(socket, 0);
		}
		else if (socket->m_Type == E_值类型::e_Type_I32) {
			m_转换值 = DEF_I32插座数据(socket, 0);
		}
		else if (socket->m_Type == E_值类型::e_Type_F32) {
			m_转换值 = DEF_Max(0, *((float32*)(dynamic_cast<C_F32插座*>(socket)->f_getData(连接线ID))));
		}
		else if (socket->m_Type == E_值类型::e_Type_F32_1D) {
			const auto* v = DEF_F32插座_1D数据(socket);
			m_转换值 = v->count;
		}
		else if (socket->m_Type == E_值类型::e_Type_I8_1D) {
			const auto* v = DEF_I8插座_1D数据(socket);
			m_转换值 = v->count;
		}
		else if (socket->m_Type == E_值类型::e_Type_I32_1D) {
			const auto* v = DEF_I32插座_1D数据(socket);
			m_转换值 = v->count;
		}
		else if (socket->m_Type == E_值类型::e_Type_UI32_1D) {
			const auto* v = DEF_UI32插座_1D数据(socket);
			m_转换值 = v->count;
		}
		else if (socket->m_Type == E_值类型::e_Type_Vec2_1D) {
			const auto* v = DEF_Vec2插座_1D数据(socket);
			m_转换值 = v->count;
		}
		else if (socket->m_Type == E_值类型::e_Type_Vec3_1D) {
			const auto* v = DEF_Vec3插座_1D数据(socket);
			m_转换值 = v->count;
		}
		else if (socket->m_Type == E_值类型::e_Type_Vec4_1D) {
			const auto* v = DEF_Vec4插座_1D数据(socket);
			m_转换值 = v->count;
		}
		else if (socket->m_Type == E_值类型::e_Type_iVec2_1D) {
			const auto* v = DEF_iVec2插座_1D数据(socket);
			m_转换值 = v->count;
		}
		else if (socket->m_Type == E_值类型::e_Type_iVec3_1D) {
			const auto* v = DEF_iVec3插座_1D数据(socket);
			m_转换值 = v->count;
		}
		else if (socket->m_Type == E_值类型::e_Type_Array) {
			const auto& v = DEF_数组插座数据(socket, 0);
			m_转换值 = v->count;
		}
		else if (socket->m_Type == E_值类型::e_Type_F32_Array1D) {
			const auto& v = DEF_F32_Array1D插座数据(socket, 0);
			if (v->size()) {
				m_转换值 = (*v).at(0);
			}
		}
		else if (socket->m_Type == E_值类型::e_Type_Object_1D) {
			const auto& body = *DEF_物体插座_1D数据(socket, 0);
			m_转换值 = body.count;
		}
		else if (socket->m_Type == E_值类型::e_Type_Object_Array1D) {
			const auto& body = *DEF_物体插座_Array1D数据(socket, 0);
			m_转换值 = body.size();
		}
		else if (socket->m_Type == E_值类型::e_插座Type_物理体) {
			m_转换值 = 1;
		}
		else if (socket->m_Type == E_值类型::e_插座Type_物理体_Array1D) {
			const auto& body = *DEF_物理体插座_1D数据(socket, 连接线ID);
			m_转换值 = body.size();
		}
		else if (socket->m_Type == E_值类型::e_插座Type_引用数据) {
			auto* data = DEF_引用插座数据(socket, 连接线ID);

			switch (data->m_Type) {
			case E_值类型::e_Type_I32:
				m_转换值 = *((int32*)data->m_Data);
				break;
			case E_值类型::e_Type_F32:
				m_转换值 = uint32(*((float32*)(data->m_Data)));
				break;
			case E_值类型::e_Type_UI32:
				m_转换值 = *((uint32*)(data->m_Data));
				break;
			default:
				break;
			}
		}

		m_Value = &m_转换值;
	}
	else if(!m_映射指针) {
		m_Value = &m_默认值;
	}
	//this;
	return m_Value;
}

void C_UI32插座::f_setData(void* data, uint8 线程ID) {
	if (data) {
		(*m_Value) = *((uint32*)data);
		m_映射指针 = true;
	}
	else {
		m_Value = &m_默认值;
		m_映射指针 = false;
	}
	
}

std::string C_UI32插座::f_构建变量代码(int32 loc) {
	C_插座基类* socket = f_getLinkOutSocket(loc);

	std::string code;
	if (socket) {
		if(socket->m_Type == E_值类型::e_Type_UI32) {
			m_Code = socket->f_getCode(loc);
			return "";
		}
		
		m_Code = m_pNode->f_getName() + f_getName() + f_整数值转字符串(loc);
		code += "uint32 " + m_Code + " = ";
		
		switch (socket->m_Type) {
			case E_值类型::e_Type_I8:
			case E_值类型::e_Type_F32:
			case E_值类型::e_Type_F64:
			case E_值类型::e_Type_I64:
			case E_值类型::e_Type_UI64:
			case E_值类型::e_Type_I32: {
				code += "uint32(" + socket->f_getCode(loc) + ");\n";
				break;
			}

			case E_值类型::e_Type_多边形边: {
				m_Code = m_pNode->f_getName() + f_getName();
				code = f_代码构建_多边形边数组数量(m_Code, socket->f_getCode(loc));
				break;
			}
			case E_值类型::e_Type_Vec3: {
				m_Code = m_pNode->f_getName() + f_getName();
				code = f_代码构建_取vec3数组数量(m_Code, socket->f_getCode(loc));
				break;
			}

			case E_值类型::e_Type_Array:
			case E_值类型::e_Type_I8_1D:
			case E_值类型::e_Type_I32_1D:
			case E_值类型::e_Type_F32_1D:
			case E_值类型::e_Type_Vec2_1D: 
			case E_值类型::e_Type_Vec3_1D:
			case E_值类型::e_Type_Vec3_2D:
			case E_值类型::e_Type_Vec4_1D:
			case E_值类型::e_Type_iVec2_1D:
			case E_值类型::e_Type_iVec3_1D:
			case E_值类型::e_Type_iVec3_2D:
			case E_值类型::e_Type_UI32_2D:
			case E_值类型::e_Type_多边形边1D:
			case E_值类型::e_Type_多边形元素1D: {
				code += socket->f_getCode(loc) + "->count;\n";
				break;
			}
			default:
				return socket->f_getCode(loc);
		}

		return code;
	}

	return C_插座基类::f_构建变量代码(loc);
}

void C_UI32插座::f_绑定指针(void* data) {
	if (m_Value == data) return;

	if (!m_映射指针) {
		free(m_Value);
	}
	m_Value = (uint32*)data;
	m_映射指针 = true;
}

bool C_UI32插座::f_接入插座是否匹配(E_值类型 type) {
	switch (type) {
	case E_值类型::e_插座Type_引用数据:
	case E_值类型::e_Type_F32:
	case E_值类型::e_Type_F64:
	case E_值类型::e_Type_I64:
	case E_值类型::e_Type_UI64:
	case E_值类型::e_Type_I8:
	case E_值类型::e_Type_I32:
	case E_值类型::e_Type_UI32:
	case E_值类型::e_Type_I8_1D:
	case E_值类型::e_Type_I32_1D:
	case E_值类型::e_Type_F32_1D:
	case E_值类型::e_Type_Vec3_1D:
	case E_值类型::e_Type_Vec3_2D:
	case E_值类型::e_Type_Vec4_1D:
	case E_值类型::e_Type_uVec2_1D:
	case E_值类型::e_Type_uVec3_1D:
	case E_值类型::e_Type_iVec2_1D:
	case E_值类型::e_Type_iVec3_1D:
	case E_值类型::e_Type_iVec3_2D:
	case E_值类型::e_Type_UI32_2D:
	//case E_值类型::e_Type_多边形边:
	case E_值类型::e_Type_多边形边1D:
	case E_值类型::e_Type_Object_1D :
	case E_值类型::e_Type_Object_Array1D :
	case E_值类型::e_Type_Array:
		return true;
	}
	return false;
}

void C_UI32插座::f_读取(FILE* f) {
	C_插座基类::f_读取(f);

	fread(m_Value, sizeof(uint32), 1, f);
}

void C_UI32插座::f_写入(FILE* f) {
	C_插座基类::f_写入(f);

	fwrite(m_Value, sizeof(uint32), 1, f);
}

void C_UI32插座::f_Copy(const C_插座基类* node) {
	C_插座基类::f_Copy(node);
	(*m_Value) = *(dynamic_cast<const C_UI32插座*>(node)->m_Value);
}

PyObject * C_UI32插座::f_bl_传入数据(PyObject * bl_data) {
	*m_Value = PyLong_AsLong(bl_data);
	return 0;
}

PyObject * C_UI32插座::f_输出_bl数据(PyObject * bl_data) {
	PyObject* data = 0;
	if (bl_data == (PyObject*)uint64(0xffffffff)) {
		data = Py_BuildValue("[i]", DEF_I32插座数据(this, 0));
	}
	else {
		data = Py_BuildValue("i", DEF_I32插座数据(this, 0));
	}
	return data;
}







C_UI64插座::C_UI64插座(std::wstring name) :C_插座基类(name, E_值类型::e_Type_UI64) {
	m_Value = 0;
}

C_UI64插座::~C_UI64插座() {
	C_插座基类::~C_插座基类();
}

void* C_UI64插座::f_getData(uint8 当前插座连接线ID) {
	C_插座基类* socket = f_getLinkOutSocket(当前插座连接线ID);
	if (socket) {
		if (socket->m_Type == E_值类型::e_Type_UI32) {
			m_Value = DEF_UI32插座数据(socket, 当前插座连接线ID);
		}else if (socket->m_Type == E_值类型::e_Type_I32) {
			m_Value = DEF_Max(0, DEF_I32插座数据(socket, 当前插座连接线ID));
		} else if (socket->m_Type == E_值类型::e_Type_F32) {
			m_Value = DEF_Max(0, DEF_F32插座数据(socket, 当前插座连接线ID));
		}
		else if (socket->m_Type == E_值类型::e_Type_Object_Array1D) {
			auto& objs = *DEF_物体插座_Array1D数据(socket, 当前插座连接线ID);
			m_Value = objs.size();
		}
	}
	else {
		return &m_默认值;
	}
	return &m_Value;
}

void C_UI64插座::f_setData(void* data, uint8 线程ID) {
	m_Value = *((uint64*)data);
}

inline E_JIT_FunParam C_UI64插座::f_getJIT参数(uint8 线程ID, uint16 in_ID) { 
	m_JIT参数ID = in_ID;  
	E_JIT_FunParam 参数;
	参数.m_data = f_getData(线程ID);
	参数.m_type = m_Type;
	参数.m_Num = 0;
	return 参数;
}

std::string C_UI64插座::f_构建变量代码(int32 loc) {
	std::string code;
	C_插座基类* socket = f_getLinkOutSocket(loc);
	auto* rt = f_getNode()->f_getThis节点树();

	if (socket) {
		if (socket->m_Type == E_值类型::e_Type_UI64) {
			m_Code = socket->f_getCode(loc);
			return "";
		}

		m_Code = m_pNode->f_getName() + f_getName() + f_整数值转字符串(loc) + "new_val_to_ui64";
		switch (socket->m_Type) {
		case E_值类型::e_Type_I32: 
		case E_值类型::e_Type_F32: {
			code += m_Code + " = " + socket->f_getCode(loc) + ";\n";
			break;
		}

		case E_值类型::e_Type_多边形边1D:
		case e_Type_F32_1D:
		case e_Type_Vec2_1D:
		case e_Type_Vec3_1D:
		case E_值类型::e_Type_多边形元素1D: {
			code += m_Code + " = " + socket->f_getCode(loc) + "->count;\n";
			break;
		}
		}
	}
	else {
		C_插座基类::f_构建变量代码(loc);
	}

	return code;
}

bool C_UI64插座::f_接入插座是否匹配(E_值类型 type) {
	switch (type) {
	case e_Type_I32:
	case e_Type_UI32:
	case e_Type_I64:
	case e_Type_UI64:
	case e_Type_F32:
	case e_Type_F64:
	case e_Type_I32_1D:
	case e_Type_F32_1D:
	case e_Type_Vec2_1D:
	case e_Type_Vec3_1D:
	case e_Type_uVec2_1D:
	case e_Type_uVec3_1D:
	case E_值类型::e_Type_多边形边1D:
	case E_值类型::e_插座Type_引用数据:
		return true;
	}
	return false;
}

void C_UI64插座::f_读取(FILE* f) {
	C_插座基类::f_读取(f);

	fread(&m_Value, sizeof(uint64), 1, f);
}

void C_UI64插座::f_写入(FILE* f) {
	C_插座基类::f_写入(f);

	fwrite(&m_Value, sizeof(uint64), 1, f);
}











C_点距八叉树插座::C_点距八叉树插座(std::wstring name) :C_插座基类(name, E_值类型::e_插座Type_八叉树) {
	m_Value = nullptr;
}

C_点距八叉树插座::~C_点距八叉树插座() {

}

void* C_点距八叉树插座::f_getData(uint8 线程ID) {
	C_插座基类* socket = f_getLinkOutSocket();
	if (socket) {
		if (socket->m_Type == E_值类型::e_插座Type_八叉树) {
			return DEF_点距八叉树插座Value(socket, 0);
		}
		else if (socket->m_Type == E_值类型::e_Type_I32) {
			//m_Value = DEF_Max(0, DEF_I32插座Value(socket, 0));
		}
		else if (socket->m_Type == E_值类型::e_Type_F32) {
			//m_Value = DEF_Max(0, DEF_F32插座Value(socket, 0));
		}
	}
	return m_Value;
}

void C_点距八叉树插座::f_setData(void* data, uint8 线程ID) {
	m_Value = (S_点距八叉树*)data;
}














C_体素插座::C_体素插座(std::wstring name) : C_插座基类(name, E_值类型::e_Type_体素) {
	m_Value = nullptr;
}

C_体素插座::~C_体素插座() {
	C_插座基类::~C_插座基类();
}

void* C_体素插座::f_getData(uint8 线程ID) {
	C_插座基类* socket = f_getLinkOutSocket();
	if (socket) {
		if (socket->m_Type == E_值类型::e_Type_体素) {
			return socket->f_getData(线程ID);
		}
		else if (socket->m_Type == E_值类型::e_Type_I32) {
			//m_Value = DEF_Max(0, DEF_I32插座Value(socket, 0));
		}
		else if (socket->m_Type == E_值类型::e_Type_F32) {
			//m_Value = DEF_Max(0, DEF_F32插座Value(socket, 0));
		}
	}
	return m_Value;
}

void C_体素插座::f_setData(void* data, uint8 线程ID) {
	m_Value = (S_体素*)data;
}

C_2D曲线采样值插座::C_2D曲线采样值插座(std::wstring name) : C_插座基类(name, E_值类型::e_Type_2D曲线采样) {
}

C_2D曲线采样值插座::~C_2D曲线采样值插座() {
	C_插座基类::~C_插座基类();
}

void* C_2D曲线采样值插座::f_getData(uint8 线程ID) {
	return nullptr;
}

void C_2D曲线采样值插座::f_setData(void* data, uint8 线程ID) {

}






